package com.glory.cqaospda.bean

import android.content.Context
import androidx.fragment.app.FragmentManager
import com.google.gson.annotations.SerializedName
import java.util.*


data class BaseResponseBean<T>(
    var response: Response<T> = Response(),

//    var tipDialog: FreeUI_GeneralFragmentDialog? = null
) {
    data class Response<T>(
        var body: T? = null,
        @SerializedName("return")
        var mReturn: Return = Return(),
        var header: HeaderBean = HeaderBean()
    )

    data class Return(
        var returncode: String = "", // 200
        var returnmessage: String = "" // 操作成功
    )

    fun isSuccess(
        context: Context?,
        isHaveBody: Boolean,
        fragmentManager: FragmentManager?
    ): Boolean {
        var ReturnCode = response.mReturn.returncode
        var ReturnMessage: String? = response.mReturn.returnmessage

        return if (ReturnCode == "SUCCESS") {
            if (isHaveBody) {
                if (response.body == null) {
                    showFailDialog("暂无请求内容", fragmentManager!!)
                    false
                } else {
                    if (response.body is ArrayList<*>) {
                        if ((response.body as ArrayList<*>).size > 0) {
                            true
                        } else {
                            showFailDialog("暂无请求数据", fragmentManager!!)
                            false
                        }
                    } else {
                        true
                    }
                }
            } else {
                true
            }
        } else {
            showFailDialog(ReturnMessage!!, fragmentManager!!)
            false
        }
    }

    private fun showFailDialog(message: String, fragmentManager: FragmentManager) {
//        tipDialog = FreeApi_DialogUtils.getConfirmDialog(MyApp.app, "确定", message) {}
//        tipDialog!!.show(fragmentManager, "DIALOG")
    }

}
